const stu = {
    name: '瑞斯邦' ,
    age: 22 ,
    hometown: '绵阳'
}

const template = '大家好，我是${name}，我来自${hometown}，今年${age}岁';

// 匹配 ${name} 、${hometown} 、${age}
const regexp = /\$\{\w+\}/; 

// 匹配 name 、hometown 、age
const expression = /\w+/;

let str = template ;

// 当 str 中存在匹配于 regexp 的内容时 test 返回 true
while( regexp.test( str ) ){
    let result = regexp.exec( str );
    let matched = result[ 0 ];
    result = expression.exec( matched );
    let property = result[ 0 ];
    console.log( matched , property );
    str = str.replace( matched , stu[ property ] );
}

console.log( str );